package com.dlwx.parttimetalent.views;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.DatePicker;
import android.widget.NumberPicker;
import android.widget.TextView;

import com.dlwx.parttimetalent.R;
import com.dlwx.parttimetalent.inter.GetAgeInter;
import com.dlwx.parttimetalent.utils.DateUtil;
import com.flyco.dialog.widget.base.BaseDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/11/21.
 */

public class AgeDialog extends BaseDialog {
    @BindView(R.id.datepicker)
    DatePicker datepicker;
    @BindView(R.id.tv_confirm)
    TextView tvConfirm;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    private Context context;
    private GetAgeInter inter;
    private boolean isCurrent;

    public AgeDialog(Context context,GetAgeInter inter,boolean isCurrent) {
        super(context);
        this.context = context;
        this.inter=inter;
        this.isCurrent=isCurrent;

    }

    @Override
    public View onCreateView() {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_age, null);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void setUiBeforShow() {
        if(isCurrent){
//            String date=DateUtil.getTodayDate();
//            String[] dates=date.split("-");
//            if(dates.length>2){
//                int year=Integer.valueOf(dates[0]);
//                int month=Integer.valueOf(dates[1]);
//                int day=Integer.valueOf(dates[2]);
//                LogUtils.i(year+"--"+month+"--"+day);
//                datepicker.init(year,month,day,null);
//            }
        }else{
            datepicker.init(1990,0,1,null);
        }
        datepicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

    }

    @OnClick({R.id.tv_confirm, R.id.tv_cancel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_confirm:
                String astro=DateUtil.getAstro(datepicker.getMonth()+1,datepicker.getDayOfMonth());
                inter.getAge(datepicker.getYear(),(datepicker.getMonth()+1),datepicker.getDayOfMonth(),astro);
//
                this.dismiss();
                break;
            case R.id.tv_cancel:
                this.dismiss();
                break;
        }
    }
}
